ssc install blindschemes
set scheme plotplain
   
clear all
***Change this line to where you have stoed the appropriate data
global ASI2009 "P:\Sid\Anil_replication\UPLOAD\Data"

global raw "$ASI2009\Extracted_from_website\ASI_2009_10-Detailed_new format\survey0\data\DOCUMENTS"
global data "$ASI2009\Stata_data_raw\ASI_2009_10\data"
global results "$ASI2009\\Stata_data_raw\ASI_2009_10\results"


cap mkdir "$results"
cap mkdir "$data"

import delimited "$raw\asi10m.TXT"

gen block=substr(v1,3,1)

preserve
**# Bookmark B
***Block B
keep if block=="B"

gen DSL=substr(v1,5,6)
gen ISO=substr(v1,19,1)
replace ISO="0" if ISO=="2"

foreach var in DSL ISO{
	destring `var', replace
}


save "$data\asi2009_b.dta", replace
restore

preserve
**# Bookmark A
**
keep if block=="A"
gen DSL=substr(v1,5,6)
gen PSL=substr(v1,11,5)
gen nic_08=substr(v1,21,5)
gen state=substr(v1,26,2)
gen rural=substr(v1,30,1)
gen export=substr(v1,104,3)

foreach var in DSL nic_08 state rural export{
	destring `var', replace
}
save "$data\asi2009_a.dta", replace
restore

preserve
**# Bookmark #3
keep if block=="J"
gen DSL=substr(v1,5,6)
gen ASICC=substr(v1,13,5)
gen unit_price=substr(v1,126,15)
foreach var in DSL ASICC unit_price{
	destring `var', replace
}
save "$data\asi2009_j.dta", replace
restore

preserve
**# Bookmark #3
keep if block=="E"
gen DSL=substr(v1,5,6)
gen labour=substr(v1,29,10)
gen labour_emp=substr(v1,39,8)

foreach var in DSL labour labour_emp{
	destring `var', replace
}

bys DSL: egen total_labour=total(labour)
bys DSL: egen total_labour_emp=total(labour_emp)
keep DSL total*
duplicates drop
save "$data\asi2009_e.dta", replace
restore

**# Bookmark #5

use "$data\asi2009_a.dta", clear

merge 1:1 DSL using "$data\asi2009_b.dta"
drop _merge

merge 1:1 DSL using "$data\asi2009_e.dta"
drop _merge

merge 1:m DSL using "$data\asi2009_j.dta"

**# Bookmark #6
gen ln_price=ln(unit_price)
gen ln_L=ln(total_labour_emp)
gen export_dummy=0
replace export_dummy=1 if export>0 & !missing(export)
replace export_dummy=. if missing(export)


label variable ln_price "log(price)"
label variable export "Export (percentage)"
label variable ln_L "log(Labor)"
label variable ISO "ISO certified"
label variable export_dummy "Exporter"

eststo clear
eststo: reghdfe ln_price ISO, absorb(ASICC#state#rural) vce(cluster ASICC)
	estadd local Fixed1 "Yes"
	estadd local Fixed2 "Yes"
	estadd local Fixed3 "-"
	estadd local Fixed4 "-"
	estadd local Cluster "Product"
eststo: reghdfe ln_price export_dummy, absorb(ASICC#state#rural) vce(cluster ASICC)
estadd local Fixed1 "Yes"
	estadd local Fixed2 "-"
	estadd local Fixed3 "Yes"
	estadd local Fixed4 "-"
	estadd local Cluster "Product"
esttab, se b(a2) ar2 star(* 0.10 ** 0.05 *** 0.01) nocon label legend replace scalars("Fixed1 State x Rural x Product FE"  "Cluster SE clusters:") drop(_*)
esttab using $results\T4_20250404_2009_ASIa.tex, se b(a2) ar2 star(* 0.10 ** 0.05 *** 0.01) nocon label legend replace scalars("Fixed1 State x Rural x Product FE"  "Cluster SE clusters:") drop(_*)



eststo clear
eststo: reghdfe ISO ln_L, absorb(ASICC#state#rural) vce(cluster ASICC)
	estadd local Fixed1 "Yes"
	estadd local Fixed2 "Yes"
	estadd local Fixed3 "-"
	estadd local Fixed4 "-"
	estadd local Cluster "Product"
eststo: reghdfe export_dummy ln_L, absorb(ASICC#state#rural) vce(cluster ASICC)
estadd local Fixed1 "Yes"
	estadd local Fixed2 "-"
	estadd local Fixed3 "Yes"
	estadd local Fixed4 "-"
	estadd local Cluster "Product"
esttab, se b(a2) ar2 star(* 0.10 ** 0.05 *** 0.01) nocon label legend replace scalars("Fixed1 State x Rural x Product FE"  "Cluster SE clusters:") drop(_*)
esttab using $results\T5_20250404_2009_ASIb.tex, se b(a2) ar2 star(* 0.10 ** 0.05 *** 0.01) nocon label legend replace scalars("Fixed1 State x Rural x Product FE"  "Cluster SE clusters:") drop(_*)




